# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=java-postgresql-jdbc
_pkgname=postgresql-jdbc
pkgver=42.6.2
pkgrel=0
pkgdesc="Java JDBC 4.2 (JRE 8+) driver for PostgreSQL database"
url="https://jdbc.postgresql.org/"
# riscv64: RISCV_FLUSH_ICACHE not available
# aarch64: jdk segfaults building it
arch="noarch !aarch64 !riscv64"
license="BSD-3-Clause"
makedepends="java-jdk gradle"
source="$pkgname-$pkgver.tar.gz::https://github.com/pgjdbc/pgjdbc/archive/REL$pkgver.tar.gz
	increase-max-memory.patch
	"
options="!check net" # tests require running postgres server
builddir="$srcdir/pgjdbc-REL$pkgver"

# secfixes:
#   42.6.2-r0:
#     - CVE-2024-1597
#   42.5.1-r0:
#     - CVE-2022-41946
#   42.4.2-r0:
#     - CVE-2022-31197
#   42.2.25-r0:
#     - CVE-2022-21724
#     - CVE-2020-13692

build() {
	# Note: Gradle downloads quite many dependencies, but
	# these are used only for building, not bundled to the final JAR.
	export JAVA_HOME="/usr/lib/jvm/default-jvm"
	gradle --no-daemon -p pgjdbc jar
}

check() {
	gradle --no-daemon -p pgjdbc test
}

package() {
	install -Dm644 ./pgjdbc/build/libs/postgresql-$pkgver-SNAPSHOT.jar \
		"$pkgdir"/usr/share/java/$_pkgname-$pkgver.jar
	ln -s $_pkgname-$pkgver.jar "$pkgdir"/usr/share/java/$_pkgname.jar
}

sha512sums="
95151fd23480362e9a0ea18e31db109d636a46f925097274d0d2f15689ca3776438fa703193d1320614787597bac9d696d8b60e25138df64e232705af07dfe86  java-postgresql-jdbc-42.6.2.tar.gz
5f761b43c5350e178e1f49e03625f01c61200033c220b93dded04069e96160d03bb7ca9ace9d733c7d14a9569d853772cc9df97e284da8e3daed4fcaf8313c8b  increase-max-memory.patch
"
